package com.huiyeji.dynamic.core.builder;

import com.huiyeji.dynamic.core.exception.IllegalDynamicObjectException;
import com.huiyeji.dynamic.core.provider.DynamicAnnoMethodProvider;
import com.huiyeji.dynamic.core.provider.DynamicMethodProvider;
import com.huiyeji.dynamic.core.DynamicObjectInfo;
import com.huiyeji.dynamic.core.annotations.*;

import java.util.Arrays;
import java.util.Collections;

/**
 * @author Huiyeji
 */
@DynamicBean("Dynamic")
public class DynamicAnnotationObjectBuilder extends AbstractDynamicBuilder {

    @Override
    public DynamicObjectInfo initialize(Object object) {
        Class<?> aClass = object.getClass();

        if (aClass.isAnnotationPresent(Private.class)){
            throw new IllegalDynamicObjectException("The class 【"+aClass.getName()+"】 is a private dynamic class !");
        }

        String name = aClass.getSimpleName();
        if (aClass.isAnnotationPresent(DynamicBean.class)){
            DynamicBean annotation = aClass.getAnnotation(DynamicBean.class);
            name = annotation.value() == null || "".equals(annotation.value()) ? name : annotation.value();
        }
        return new DynamicObjectInfo(name,object);
    }
}
